import { Button, Checkbox, Form, Input,message } from 'antd';
import React from 'react';
import axios from '../utils/axios';
import {useNavigate} from "react-router-dom"
const App = () => {
  const navigate = useNavigate()
  const onFinish = (values) => {
     //
     axios.get("/login1",{params:values}).then(res=>{
         console.log(res.data);
         if (res.data.code === 1) {
            navigate("/home/testpaper")
            message.success("登陆成功")
         } else if (res.data.code === 0) {
            message.error("用户名密码错误")
         }
         else {
           message.success("注册成功，即将自动登陆")
           setTimeout(()=>{
            navigate("/home/testpaper")
           },2000)
         }
     })
    console.log('Success:', values);
  };

  const onFinishFailed = (errorInfo) => {
    console.log('Failed:', errorInfo);
  };

  return (
    <Form
      name="basic"
      labelCol={{
        span: 8,
      }}
      wrapperCol={{
        span: 8,
      }}
      onFinish={onFinish}
      onFinishFailed={onFinishFailed}
      autoComplete="off"
    >
      <Form.Item
        label="Username"
        name="username"
        rules={[
          {
            required: true,
            message: 'Please input your username!',
          },
        ]}
      >
        <Input />
      </Form.Item>

      <Form.Item
        label="Password"
        name="password"
        rules={[
          {
            required: true,
            message: 'Please input your password!',
          },
        ]}
      >
        <Input.Password />
      </Form.Item>
      <Form.Item
        wrapperCol={{
          offset: 8,
          span: 16,
        }}
      >
        <Button type="primary" htmlType="submit">
          登陆
        </Button>
      </Form.Item>
    </Form>
  );
};

export default App;